package com.vercon.moensmart.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.vercon.moensmart.R
import com.vercon.moensmart.adapter.base.BaseAdapter
import com.vercon.moensmart.databinding.ItemHealthTargetLayoutBinding
import com.vercon.moensmart.mode.HealthMeasureTarget

class HealthTargetAdapter (context: Context?) : BaseAdapter<ItemHealthTargetLayoutBinding, HealthMeasureTarget>(context) {

    override fun baseViewHolder(parent: ViewGroup): BaseViewHolder {
        val binding: ItemHealthTargetLayoutBinding = ItemHealthTargetLayoutBinding.inflate(LayoutInflater.from(context), parent, false)
        return ViewHolder(binding)
    }

    override fun bindItemView(viewHolder: BaseViewHolder?, position: Int, data: HealthMeasureTarget, total: Int) {
        viewHolder?.mBinding?.tvName?.text = data.getTitle(context)
        viewHolder?.mBinding?.tvValue?.text = data.value
        viewHolder?.mBinding?.tvValueUnit?.text = data.unit

        viewHolder?.mBinding?.tvContent?.text = data.getIsNormalTip(context)
        if(data.isNormal){
            viewHolder?.mBinding?.tvContent?.setTextColor(context!!.getColor(com.vercon.common.R.color.color_4DB468))
            viewHolder?.mBinding?.igValueStateIcon?.setBackgroundResource(R.mipmap.ic_health_value_normal)
            viewHolder?.mBinding?.tvIsNormalText?.text = "正常"
            viewHolder?.mBinding?.tvIsNormalText?.setBackgroundResource(R.drawable.bg_normal)
        }else{
            viewHolder?.mBinding?.igValueStateIcon?.setBackgroundResource(R.mipmap.ic_health_value_abnormal)
            viewHolder?.mBinding?.tvContent?.setTextColor(context!!.getColor(com.vercon.common.R.color.color_FF9257))
            viewHolder?.mBinding?.tvIsNormalText?.text = "异常"
            viewHolder?.mBinding?.tvIsNormalText?.setBackgroundResource(R.drawable.bg_abnormal)
        }
        viewHolder?.itemView?.setOnClickListener {
            mItemListener?.onItemClickListener(viewHolder.itemView, data,position)
        }
    }

    inner class ViewHolder(itemBinding: ItemHealthTargetLayoutBinding) : BaseViewHolder(itemBinding)
}